import pytest

from api.order_api.service_order_api.service_order_api import serviceOrderApi
from utils.utils import _assert

# # 创建服务订单--》查询服务订单》---》驳回订单--->删除订单
class TestServiceOrder02:

    @pytest.mark.run(order=1)
    def test01_order_create(self):
        """
        创建服务订单
        :return:
        """
        # 商店编号
        storeId = serviceOrderApi().store().json()['data']["records"][0].get("storeId")
        # 用户编号
        userId = serviceOrderApi().userID(storeId).json()['data']['records'][0].get("id")
        # 商品编号
        GoodsId = serviceOrderApi().storeGoods().json()['data']['records'][0].get("goodsId")
        # 服务价格
        price = serviceOrderApi().storeGoods().json()['data']['records'][0].get("price")
        # 发送接口请求
        global orderCode, id, response_
        response_ = serviceOrderApi().order_create(storeId=storeId, userId=userId, goodsId=GoodsId, Price=price)

        orderCode = response_.json()['data']['orderCode']
        id = response_.json()['data']['id']
        # 声明全局变量

        # 断言
        _assert(response_, 200, 0, True)

    @pytest.mark.run(order=2)
    def test02_all_order_search(self):
        """
        查询服务订单接口
        :return:
        """
        response = serviceOrderApi().all_order_search(orderCode=orderCode)
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=3)
    def test03_order_examineRefuse(self):
        """
        驳回订单
        :return:
        """
        response = serviceOrderApi().order_examineRefuse("好好学习天天向上",orderId=id)
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=4)
    def test04_order_orderDelete(self):
        """
        删除服务订单
        :return:
        """
        ""
        response = serviceOrderApi().order_orderDelete(orderId=id)
        _assert(response, 200, 0, True)